<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>Android基础--网络编程 | 不忘初心</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="导语  网络编程介绍">
<meta property="og:type" content="article">
<meta property="og:title" content="Android基础--网络编程">
<meta property="og:url" content="http://example.com/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/index.html">
<meta property="og:site_name" content="不忘初心">
<meta property="og:description" content="导语  网络编程介绍">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2014-10-13T01:44:06.000Z">
<meta property="article:modified_time" content="2017-07-10T06:58:26.000Z">
<meta property="article:author" content="wxyass">
<meta property="article:tag" content="Android基础">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="不忘初心" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">不忘初心</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-基础/基础--网络编程" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/" class="article-date">
  <time class="dt-published" datetime="2014-10-13T01:44:06.000Z" itemprop="datePublished">2014-10-13</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Android%E5%9F%BA%E7%A1%80/">Android基础</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      Android基础--网络编程
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h4 id="导语"><a href="#导语" class="headerlink" title="导语"></a>导语</h4><blockquote>
<p> 网络编程介绍  </p>
</blockquote>
<span id="more"></span> 

<h1 id="一、网络图片查看器"><a href="#一、网络图片查看器" class="headerlink" title="一、网络图片查看器"></a>一、网络图片查看器</h1><h3 id="1-1-主线程网络图片查看器"><a href="#1-1-主线程网络图片查看器" class="headerlink" title="1.1 主线程网络图片查看器"></a>1.1 主线程网络图片查看器</h3><ul>
<li><p>1 确定图片的网址</p>
<pre><code>  //确定图片的网址
  String address = &quot;http://192.168.1.102:8080/dd.jpg&quot;;
</code></pre>
</li>
<li><p>2 发送http请求</p>
<pre><code>  URL url = new URL(address);
  //获取连接对象，并没有建立连接
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  //设置连接和读取超时
  conn.setConnectTimeout(5000);
  conn.setReadTimeout(5000);
  //设置请求方法，注意必须大写
  conn.setRequestMethod(&quot;GET&quot;);
  //建立连接，发送get请求
  //conn.connect();
  //建立连接，然后获取响应吗，200说明请求成功
  conn.getResponseCode();
</code></pre>
</li>
<li><p>3 服务器的图片是以流的形式返回给浏览器的 </p>
<pre><code>  //拿到服务器返回的输入流
  InputStream is = conn.getInputStream();
  //把流里的数据读取出来，并构造成图片
  Bitmap bm = BitmapFactory.decodeStream(is);
</code></pre>
</li>
<li><p>4 把图片设置为ImageView的显示内容，直接在主线程刷新UI页面</p>
<pre><code>  ImageView iv = (ImageView) findViewById(R.id.iv);
     iv.setImageBitmap(bm);
</code></pre>
</li>
<li><p>5 添加权限</p>
</li>
</ul>
<h3 id="1-2-主线程不能被阻塞"><a href="#1-2-主线程不能被阻塞" class="headerlink" title="1.2 主线程不能被阻塞"></a>1.2 主线程不能被阻塞</h3><ul>
<li>在Android中，主线程被阻塞会导致应用不能刷新ui界面，不能响应用户操作，用户体验将非常差</li>
<li>主线程阻塞时间过长，系统会抛出ANR异常</li>
<li>ANR：Application Not Response；应用无响应</li>
<li>任何耗时操作都不可以写在主线程</li>
<li>因为网络交互属于耗时操作，如果网速很慢，代码会阻塞，所以网络交互的代码不能运行在主线程  </li>
</ul>
<h3 id="1-3只有主线程能刷新ui"><a href="#1-3只有主线程能刷新ui" class="headerlink" title="1.3只有主线程能刷新ui"></a>1.3只有主线程能刷新ui</h3><ul>
<li>刷新ui的代码只能运行在主线程，运行在子线程是没有任何效果的</li>
<li>如果需要在子线程中刷新ui，使用消息队列机制</li>
<li>主线程也叫ui线程  </li>
</ul>
<h5 id="1-3-1消息队列"><a href="#1-3-1消息队列" class="headerlink" title="1.3.1消息队列"></a>1.3.1消息队列</h5><ul>
<li><p>主线程创建时，系统会同时创建消息队列对象（MessageQueue）和消息轮询器对象（Looper）</p>
</li>
<li><p>轮询器的作用，就是不停的检测消息队列中是否有消息（Message）</p>
</li>
<li><p>Looper一旦发现Message Queue中有消息，就会把消息取出，然后把消息扔给Handler对象，Handler会调用自己的handleMessage方法来处理这条消息</p>
</li>
<li><p>handleMessage方法运行在主线程</p>
</li>
<li><p>主线程创建时，消息队列和轮询器对象就会被创建，但是消息处理器对象，需要使用时，自行创建</p>
<pre><code>  //消息队列
  Handler handler = new Handler()&#123;
      //主线程中有一个消息轮询器looper，不断检测消息队列中是否有新消息，如果发现有新消息，自动调用此方法，注意此方法是在主线程中运行的
      public void handleMessage(android.os.Message msg) &#123;
  
      &#125;
  &#125;;
</code></pre>
</li>
<li><p>在子线程中使用Handler对象往消息队列里发消息</p>
<pre><code>  //创建消息对象
  Message msg = new Message();
  //消息的obj属性可以赋值任何对象，通过这个属性可以携带数据
  msg.obj = bm;
  //what属性相当于一个标签，用于区分出不同的消息，从而运行不能的代码
  msg.what = 0;
  //发送消息
  handler.sendMessage(msg);
</code></pre>
</li>
<li><p>通过switch语句区分不同的消息</p>
<pre><code>  public void handleMessage(android.os.Message msg) &#123;
      switch (msg.what) &#123;
      //如果是1，说明属于请求成功的消息
      case 0:
          ImageView iv = (ImageView) findViewById(R.id.iv);
          Bitmap bm = (Bitmap) msg.obj;
          iv.setImageBitmap(bm);
          break;
      case 1:
          Toast.makeText(MainActivity.this, &quot;请求失败&quot;, 0).show();
          break;
      &#125;        
  &#125;  
</code></pre>
</li>
</ul>
<h3 id="1-4-加入缓存图片的功能"><a href="#1-4-加入缓存图片的功能" class="headerlink" title="1.4 加入缓存图片的功能"></a>1.4 加入缓存图片的功能</h3><ul>
<li><p>把服务器返回的流里的数据读取出来，然后通过文件输入流写至本地文件</p>
<pre><code>  //1.拿到服务器返回的输入流
  InputStream is = conn.getInputStream();
  //2.把流里的数据读取出来，并构造成图片
                      
  FileOutputStream fos = new FileOutputStream(file);
  byte[] b = new byte[1024];
  int len = 0;
  while((len = is.read(b)) != -1)&#123;
      fos.write(b, 0, len);
  &#125;
</code></pre>
</li>
<li><p>创建bitmap对象的代码改成</p>
<pre><code>  Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath());
</code></pre>
</li>
<li><p>每次发送请求前检测一下在缓存中是否存在同名图片，如果存在，则读取缓存</p>
<pre><code>  // 点击事件
  public void click(View v) &#123;
      // 图片的地址
      final String address = &quot;http://192.168.1.102:8080/dd.jpg&quot;;
      // 封装图片的缓存文件
      final File file = new File(getCacheDir(), _getFileName(address));
      // 判断图片缓存文件是否存在
      if (file.exists()) &#123;
          // 图片缓存文件存在
          Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath());
          ImageView iv = (ImageView) findViewById(R.id.iv);
          iv.setImageBitmap(bm);
      &#125; else &#123;
          // 图片缓存文件不存在
          Thread t = new Thread() &#123;
              public void run() &#123;
                  
              &#125;
          &#125;；
          t.start();
      &#125;
  &#125;
</code></pre>
</li>
</ul>
<h3 id="1-5-网络图片查看器示例"><a href="#1-5-网络图片查看器示例" class="headerlink" title="1.5 网络图片查看器示例"></a>1.5 网络图片查看器示例</h3><pre><code>public class MainActivity extends Activity &#123;
    // 主线程定义Handler
    Handler handler = new Handler() &#123;
        public void handleMessage(android.os.Message msg) &#123;
            switch (msg.what) &#123;
            case 0:
                ImageView iv = (ImageView) findViewById(R.id.iv);
                iv.setImageBitmap((Bitmap) msg.obj);
                break;
            case 1:
                Toast.makeText(MainActivity.this, &quot;请求失败&quot;, 0).show();
                break;
            &#125;
        &#125;
    &#125;;

    @Override
    protected void onCreate(Bundle savedInstanceState) &#123;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    &#125;

    // 点击事件
    public void click(View v) &#123;
        // 图片的地址
        final String address = &quot;http://192.168.1.102:8080/dd.jpg&quot;;
        // 封装图片的缓存文件
        final File file = new File(getCacheDir(), _getFileName(address));
        // 判断图片缓存文件是否存在
        if (file.exists()) &#123;
            // 图片缓存文件存在
            Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath());
            ImageView iv = (ImageView) findViewById(R.id.iv);
            iv.setImageBitmap(bm);
        &#125; else &#123;
            // 图片缓存文件不存在
            Thread t = new Thread() &#123;
                public void run() &#123;
                    try &#123;
                        // 1，2 将图片网址字符串地址封装成URL
                        URL url = new URL(address);
                        // 3 获取连接对象，此方法只是获取连接对象，方便操作参数，并不会发送请求
                        HttpURLConnection conn = (HttpURLConnection) url
                                .openConnection();
                        // 4 设置请求参数，注意大写
                        conn.setRequestMethod(&quot;GET&quot;);
                        // 连接超时
                        conn.setConnectTimeout(8000);
                        // 读取超时
                        conn.setReadTimeout(8000);
                        // 5 发送请求，建立连接（此步可不写，自动发送）
                        conn.connect();
                        // 6.获取响应码，进行判断
                        if (conn.getResponseCode() == 200) &#123;
                            // 服务器响应正常
                            // 7.拿到服务器返回的流，流里的数据，就是客户端请求的内容
                            InputStream is = conn.getInputStream();

                            // 将流里的数据(一张图片)缓存到本地
                            FileOutputStream os = new FileOutputStream(file);
                            byte[] bt = new byte[1024];
                            int len;
                            while ((len = is.read(bt)) != -1) &#123;
                                os.write(bt, 0, len);
                            &#125;
                            os.close();

                            // 将本地的缓存文件数据读取出来，并构成图片
                            Bitmap bm = BitmapFactory.decodeFile(file
                                    .getAbsolutePath());

                            // 由于子线程不能刷新UI界面，将数据发送到主线程消息队列，让主线程刷新UI页面
                            // 发送消息到消息队列
                            // 获取消息对象，//如果消息池有空消息，使用消息池的消息，如果没有，此方法会自动创建一个消息对象
                            Message msg = handler.obtainMessage();
                            // 利用消息对象携带数据
                            msg.obj = bm;
                            msg.what = 0;
                            // 将消息发送到消息队列
                            handler.sendMessage(msg);
                        &#125; else &#123;
                            // 各种情况使得客户端请求失败，或服务器端响应失败
                            // 将失败消息发送到消息队列
                            handler.sendEmptyMessage(1);
                        &#125;
                    &#125; catch (Exception e) &#123;
                        e.printStackTrace();
                    &#125;

                &#125;
            &#125;;
            t.start();
        &#125;
    &#125;

    // 获取缓存文件夹下的文件名
    public String _getFileName(String address) &#123;
        int index = address.lastIndexOf(&quot;/&quot;);
        return address.substring(index + 1);

    &#125;
&#125;
</code></pre>
<hr>
<h1 id="1-6-获取开源代码的网站"><a href="#1-6-获取开源代码的网站" class="headerlink" title="1.6 获取开源代码的网站"></a>1.6 获取开源代码的网站</h1><ul>
<li><p>code.google.com</p>
</li>
<li><p>github.com</p>
</li>
<li><p>在github搜索smart-image-view</p>
</li>
<li><p>下载开源项目smart-image-view</p>
</li>
<li><p>使用自定义组件时，标签名字要写包名</p>
<pre><code>  &lt;com.loopj.android.image.SmartImageView/&gt;
</code></pre>
</li>
<li><p>SmartImageView的使用</p>
<pre><code>  SmartImageView siv = (SmartImageView) findViewById(R.id.siv);
  siv.setImageUrl(&quot;http://192.168.1.102:8080/dd.jpg&quot;);
</code></pre>
</li>
</ul>
<hr>
<h1 id="1-7-Html源文件查看器"><a href="#1-7-Html源文件查看器" class="headerlink" title="1.7 Html源文件查看器"></a>1.7 Html源文件查看器</h1><ul>
<li><p>1 发送GET请求</p>
<pre><code>  URL url = new URL(path);
  //获取连接对象
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  //设置连接属性
  conn.setRequestMethod(&quot;GET&quot;);
  conn.setConnectTimeout(5000);
  conn.setReadTimeout(5000);
  //建立连接，获取响应吗
  if(conn.getResponseCode() == 200)&#123;
      //拿到服务器返回的流，流里的数据，就是客户端请求的内容
      InputStream is = conn.getInputStream();
  &#125;
</code></pre>
</li>
<li><p>2 获取服务器返回的流，从流中把html源码读取出来</p>
<pre><code>  byte[] b = new byte[1024];
  int len = 0;
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  while((len = is.read(b)) != -1)&#123;
      //把读到的字节先写入字节数组输出流中存起来
      bos.write(b, 0, len);
  &#125;
  //把字节数组输出流中的内容转换成字符串
  //默认使用utf-8
  text = new String(bos.toByteArray());
</code></pre>
</li>
</ul>
<p>-Html源文件查看器示例————————-</p>
<pre><code>public class MainActivity extends Activity &#123;
//主线程定义消息处理器
Handler handler = new Handler()&#123;
    public void handleMessage(android.os.Message msg) &#123;
        switch (msg.what) &#123;
        case 0:
            TextView tv = (TextView) findViewById(R.id.tv);
            tv.setText((String)msg.obj);
            break;

        case 1:
            Toast.makeText(MainActivity.this, &quot;请求失败啦啦啦么么哒&quot;, 0).show();
            break;
        &#125;
    &#125;
&#125;;
@Override
protected void onCreate(Bundle savedInstanceState) &#123;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
&#125;

//点击事件:查看html文件源码
public void click(View v)&#123;
    Thread t = new Thread()&#123;
        @Override
        public void run() &#123;
            String path = &quot;http://192.168.15.27:8080/baidu.html&quot;;
            try &#123;
                URL url = new URL(path);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod(&quot;GET&quot;);
                conn.setConnectTimeout(8000);
                conn.setReadTimeout(8000);
                
                //先发送请求，然后获取相应码
                if(conn.getResponseCode() == 200)&#123;
                    //拿到服务器返回的流，流里的数据，就是客户端请求的内容
                    InputStream is = conn.getInputStream();
                    //将输入流数据，转换为字符串
                    String text = Tools.getTextFromStream(is);
                    
                    //发送消息到消息队列，触发主界面刷新页面
                    Message msg = handler.obtainMessage();
                    msg.obj = text;
                    msg.what = 0;
                    handler.sendMessage(msg);
                    
                    
                &#125;
                else&#123;
                    handler.sendEmptyMessage(1);
                &#125;
            &#125; catch (Exception e) &#123;
                // TODO Auto-generated catch block
                e.printStackTrace();
            &#125;
        &#125;
    &#125;;
    t.start();

    
&#125;
</code></pre>
<p>}</p>
<h3 id="1-8-乱码的处理"><a href="#1-8-乱码的处理" class="headerlink" title="1.8 乱码的处理"></a>1.8 乱码的处理</h3><ul>
<li><p>乱码的出现是因为服务器和客户端码表不一致导致</p>
<pre><code>  //手动指定码表
  text = new String(bos.toByteArray(), &quot;gb2312&quot;);
</code></pre>
</li>
<li><p>在定义工具类时，将输入流数据转换为字符串，此时手动指定码表</p>
<p>  public class Tools {</p>
<pre><code>  public static String getTextFromStream(InputStream is)&#123;
      
      byte[] b = new byte[1024];
      int len;
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      try &#123;
          while((len = is.read(b)) != -1)&#123;
              bos.write(b, 0, len);
          &#125;
          
          String text = new String(bos.toByteArray());
          return text;
      &#125; catch (IOException e) &#123;
          // TODO Auto-generated catch block
          e.printStackTrace();
          return null;
      &#125;
  &#125;
</code></pre>
<p>  }</p>
</li>
</ul>
<hr>
<h1 id="二、提交数据"><a href="#二、提交数据" class="headerlink" title="二、提交数据"></a>二、提交数据</h1><h3 id="2-1-GET方式提交数据"><a href="#2-1-GET方式提交数据" class="headerlink" title="2.1 GET方式提交数据"></a>2.1 GET方式提交数据</h3><ul>
<li><p>get方式提交的数据是直接拼接在url的末尾</p>
<pre><code>  final String path = &quot;http://192.168.1.104/Web/servlet/CheckLogin?name=&quot; + name + &quot;&amp;pass=&quot; + pass;
</code></pre>
</li>
<li><p>发送get请求，代码和之前一样</p>
<pre><code>  URL url = new URL(path);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setRequestMethod(&quot;GET&quot;);
  conn.setReadTimeout(5000);
  conn.setConnectTimeout(5000);
  if(conn.getResponseCode() == 200)&#123;

  &#125;
</code></pre>
</li>
<li><p>浏览器在发送请求携带数据时会对数据进行URL编码，我们写代码时也需要为中文进行URL编码</p>
<pre><code>  String path = &quot;http://192.168.1.104/Web/servlet/CheckLogin?name=&quot; + URLEncoder.encode(name) + &quot;&amp;pass=&quot; + pass;
</code></pre>
</li>
</ul>
<p>-GET方式提交数据示例———————————————</p>
<pre><code>public class MainActivity extends Activity &#123;

//主线程定义消息处理器Handler
Handler handler = new Handler()&#123;
    public void handleMessage(android.os.Message msg) &#123;
        Toast.makeText(MainActivity.this, (String)msg.obj, 0).show();
    &#125;
&#125;;
@Override
protected void onCreate(Bundle savedInstanceState) &#123;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
&#125;

//点击事件，get提交用户名，密码
public void click(View v)&#123;
    EditText et_name = (EditText) findViewById(R.id.et_name);
    EditText et_pass = (EditText) findViewById(R.id.et_pass);
    
    String name = et_name.getText().toString();
    String pass = et_pass.getText().toString();
    
    @SuppressWarnings(&quot;deprecation&quot;)
        //客户端提交的表单数据都会被url编码
    final String path = &quot;http://192.168.15.27/Web2/servlet/LoginServlet?name=&quot; + URLEncoder.encode(name) + &quot;&amp;pass=&quot; + pass;
    
    Thread t = new Thread()&#123;
        @Override
        public void run() &#123;
            try &#123;
                URL url = new URL(path);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod(&quot;GET&quot;);
                conn.setConnectTimeout(8000);
                conn.setReadTimeout(8000);
                
                if(conn.getResponseCode() == 200)&#123;
                    //服务器成功响应，拿到服务器返回的流
                    InputStream is = conn.getInputStream();
                    //将流中的数据转成字符串
                    String text = Tools.getTextFromStream(is);
                    
                    // 发送消息到消息队列，在主线程刷新页面
                    Message msg = handler.obtainMessage();
                    msg.obj = text;
                    handler.sendMessage(msg);
                &#125;
            &#125; catch (Exception e) &#123;
                // TODO Auto-generated catch block
                e.printStackTrace();
            &#125;
        &#125;
    &#125;;
    t.start();
&#125;
&#125;

//工具类
public class Tools &#123;
    //读取输入流的数据，返回字符串
    public static String getTextFromStream(InputStream is)&#123;
        byte[] b = new byte[1024];
        int len;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try &#123;
            while((len = is.read(b)) != -1)&#123;
                bos.write(b, 0, len);
            &#125;
            String text = new String(bos.toByteArray());
            return text;
        &#125; catch (IOException e) &#123;
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        &#125;
    &#125;
&#125;
</code></pre>
<h3 id="2-2-POST方式提交数据"><a href="#2-2-POST方式提交数据" class="headerlink" title="2.2 POST方式提交数据"></a>2.2 POST方式提交数据</h3><ul>
<li><p>post提交数据是用流写给服务器的</p>
</li>
<li><p>协议头中多了两个属性</p>
<ul>
<li><p>Content-Type: application/x-www-form-urlencoded，描述提交的数据的mimetype</p>
</li>
<li><p>Content-Length: 32，描述提交的数据的长度</p>
<pre><code>  //给请求头添加post多出来的两个属性
  String data = &quot;name=&quot; + URLEncoder.encode(name) + &quot;&amp;pass=&quot; + pass;
  conn.setRequestProperty(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
  conn.setRequestProperty(&quot;Content-Length&quot;, data.length() + &quot;&quot;);
</code></pre>
</li>
</ul>
</li>
<li><p>设置允许打开post请求的流</p>
<pre><code>  conn.setDoOutput(true);
</code></pre>
</li>
<li><p>获取连接对象的输出流，往流里写要提交给服务器的数据</p>
<pre><code>  OutputStream os = conn.getOutputStream();
  os.write(data.getBytes());
</code></pre>
</li>
</ul>
<p>-POST方式提交数据—————————-</p>
<pre><code>public class MainActivity extends Activity &#123;
    //主线程定义消息处理器Handler
    Handler handler = new Handler()&#123;
        public void handleMessage(android.os.Message msg) &#123;
            Toast.makeText(MainActivity.this, (String)msg.obj, 0).show();
        &#125;
    &#125;;
    @Override
    protected void onCreate(Bundle savedInstanceState) &#123;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    &#125;

    //点击事件，post提交用户名，密码
    public void click(View v)&#123;
        EditText et_name = (EditText) findViewById(R.id.et_name);
        EditText et_pass = (EditText) findViewById(R.id.et_pass);
        
        final String name = et_name.getText().toString();
        final String pass = et_pass.getText().toString();
        
        @SuppressWarnings(&quot;deprecation&quot;)
        final String path = &quot;http://192.168.15.27/Web2/servlet/LoginServlet&quot;;
        
        Thread t = new Thread()&#123;
            @Override
            public void run() &#123;
                try &#123;
                    URL url = new URL(path);
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    conn.setRequestMethod(&quot;POST&quot;);
                    conn.setConnectTimeout(8000);
                    conn.setReadTimeout(8000);
                    
                    //拼接去要提交的数据
                    String content = &quot;name=&quot; + URLEncoder.encode(name) + &quot;&amp;pass=&quot; + pass;
                    
                    //添加post请求头中的属性
                    conn.setRequestProperty(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
                    conn.setRequestProperty(&quot;Content-Length&quot;, content.length() + &quot;&quot;);
                    
                    //设置开启客户端的输出流
                    conn.setDoOutput(true);
                    //获取客户端的输出流，客户端可以通过此流把数据传递给服务器
                    OutputStream os = conn.getOutputStream();
                    os.write(content.getBytes());
                    
                    if(conn.getResponseCode() == 200)&#123;
                        InputStream is = conn.getInputStream();
                        String text = Tools.getTextFromStream(is);
                        
                        Message msg = handler.obtainMessage();
                        msg.obj = text;
                        handler.sendMessage(msg);
                    &#125;
                &#125; catch (Exception e) &#123;
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                &#125;
            &#125;
        &#125;;
        t.start();
    &#125;
&#125;
</code></pre>
<h3 id="案例综合：新闻客户端（解析xml-ListView）"><a href="#案例综合：新闻客户端（解析xml-ListView）" class="headerlink" title="案例综合：新闻客户端（解析xml,ListView）"></a>案例综合：新闻客户端（解析xml,ListView）</h3><p>public class MainActivity extends Activity {<br>    List<News> newsList;<br>    // 主线程定义信息处理器Handler<br>    Handler handler = new Handler() {<br>        public void handleMessage(android.os.Message msg) {<br>            // 获取ListView布局文件<br>            ListView lv = (ListView) findViewById(R.id.lv);<br>            // 为ListView设置适配器<br>            lv.setAdapter(new MyAdapter());<br>        }<br>    };<br>    @Override<br>    protected void onCreate(Bundle savedInstanceState) {<br>        super.onCreate(savedInstanceState);<br>        setContentView(R.layout.activity_main);<br>        // 界面一打开，执行此方法<br>        getNewsInfo();<br>    }<br>    /**<br>     * 自定义一个复杂的BaseAdapter<br>     *<br>     * @author Administrator<br>     <em>/<br>    class MyAdapter extends BaseAdapter {<br>        @Override<br>        public int getCount() {<br>            return newsList.size();<br>        }<br>        @Override<br>        public Object getItem(int position) {<br>            // TODO Auto-generated method stub<br>            return null;<br>        }<br>        @Override<br>        public long getItemId(int position) {<br>            // TODO Auto-generated method stub<br>            return 0;<br>        }<br>        @Override<br>        public View getView(int position, View convertView, ViewGroup parent) {<br>            View view = null;<br>            ViewHolder vholder = null;<br>            News news = newsList.get(position);<br>            if (convertView == null) {<br>                // 填充器将一个布局文件，转成view对象<br>                view = View.inflate(MainActivity.this, R.layout.item_listview,null);<br>                vholder = new ViewHolder();<br>                vholder.tv_title = (TextView) view.findViewById(R.id.tv_title);<br>                vholder.tv_detail = (TextView) view<br>                        .findViewById(R.id.tv_detail);<br>                vholder.tv_comment = (TextView) view<br>                        .findViewById(R.id.tv_comment);<br>                vholder.siv = (SmartImageView) view.findViewById(R.id.iv);<br>                // 将vholder封装到view对象中，vholder会和view一起缓存起来<br>                view.setTag(vholder);<br>            } else {<br>                view = convertView;<br>                vholder = (ViewHolder) view.getTag();<br>            }<br>            vholder.tv_title.setText(news.getTitle());<br>            vholder.tv_detail.setText(news.getDetail());<br>            vholder.tv_comment.setText(news.getComment() + “条评论”);<br>            vholder.siv.setImageUrl(news.getImage());<br>            return view;<br>        }<br>        class ViewHolder {<br>            TextView tv_title;<br>            TextView tv_detail;<br>            TextView tv_comment;<br>            SmartImageView siv;<br>        }<br>    }<br>    /</em>*<br>     * 请求查看服务器端xml文件<br>     */<br>    private void getNewsInfo() {<br>        Thread t = new Thread(){<br>            public void run() {<br>                // 1查看xml文件的网址<br>                String address = “<a target="_blank" rel="noopener" href="http://192.168.1.102:8080/news.xml&quot;">http://192.168.1.102:8080/news.xml&quot;</a>;<br>                // 2封装字符串地址成URL<br>                URL url;<br>                try {<br>                    url = new URL(address);<br>                    // 3获取连接对象<br>                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();<br>                    // 4设置请求参数<br>                    conn.setRequestMethod(“GET”);<br>                    conn.setConnectTimeout(8000);<br>                    conn.setReadTimeout(8000);<br>                    // 5<br>                    // 6获取响应码，进行判断<br>                    if (conn.getResponseCode() == 200) {<br>                        // 拿到服务器返回的流，流里的数据，就是请求的内容<br>                        InputStream is = conn.getInputStream();<br>                        // 用pull解析xml<br>                        parseNewsXml(is);// (第二天讲的Android下,xml数据解析,登录演示中，<br>                                            // 实现读取之前保存在xml中的数据,并显示到控件上功能)<br>                    }<br>                } catch (Exception e) {<br>                    e.printStackTrace();<br>                }<br>            }<br>        };<br>        t.start();</p>
<pre><code>&#125;
/**
 * 解析xml数据，将数据存到news对象中，将news对象存放到newsList集合中
 * 
 * @param is
 */
private void parseNewsXml(InputStream is) &#123;
    try &#123;
        // 创建xml解析器
        XmlPullParser parser = Xml.newPullParser();
        // 初始化xml解析器，指定解析那个流，以什么编码格式解析
        parser.setInput(is, &quot;UTF-8&quot;);
        // 解析xml数据
        int type = parser.getEventType();// xml标签节点类型
        News news = null;
        while (type != XmlPullParser.END_DOCUMENT) &#123;// 循环结束的条件
            switch (type) &#123;
            case XmlPullParser.START_TAG:
                if (&quot;newslist&quot;.equals(parser.getName())) &#123;
                    newsList = new ArrayList&lt;News&gt;();
                &#125; else if (&quot;news&quot;.equals(parser.getName())) &#123;
                    news = new News();
                &#125; else if (&quot;title&quot;.equals(parser.getName())) &#123;
                    String title = parser.nextText();
                    news.setTitle(title);
                &#125; else if (&quot;detail&quot;.equals(parser.getName())) &#123;
                    String detail = parser.nextText();
                    news.setDetail(detail);
                &#125; else if (&quot;comment&quot;.equals(parser.getName())) &#123;
                    String comment = parser.nextText();
                    news.setComment(comment);
                &#125; else if (&quot;image&quot;.equals(parser.getName())) &#123;
                    String image = parser.nextText();
                    news.setImage(image);
                &#125;
                break;
            case XmlPullParser.END_TAG:
                if (&quot;news&quot;.equals(parser.getName())) &#123;
                    newsList.add(news);
                &#125;
                break;
            &#125;
            type = parser.next();
        &#125;
        // 发送一个消息到消息队列，触发handleMessage()方法
        handler.sendEmptyMessage(0);
    &#125; catch (Exception e) &#123;
        // TODO Auto-generated catch block
        e.printStackTrace();
    &#125;
&#125;
&#125;
</code></pre>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/" data-id="ckvc340qx006q5dfy2rjmcs5u" data-title="Android基础--网络编程" class="article-share-link">Share</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Android%E5%9F%BA%E7%A1%80/" rel="tag">Android基础</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E5%A4%9A%E7%BA%BF%E7%A8%8B%E6%96%AD%E7%82%B9%E7%BB%AD%E4%BC%A0%E4%B8%8B%E8%BD%BD/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Android基础--多线程断点续传下载
        
      </div>
    </a>
  
  
    <a href="/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E6%95%B0%E6%8D%AE%E5%BA%93&%E5%BC%B9%E6%A1%86/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Android基础--数据库&amp;弹框</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Activity/">Activity</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android-Studio%E4%BB%8B%E7%BB%8D/">Android Studio介绍</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android%E5%9F%BA%E7%A1%80/">Android基础</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android%E6%A8%A1%E6%9D%BF/">Android模板</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/BaseRecyclerViewAdapterHelper/">BaseRecyclerViewAdapterHelper</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Bug%E9%97%AE%E9%A2%98/">Bug问题</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Button/">Button</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/EditText/">EditText</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Fragment/">Fragment</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Gradle/">Gradle</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/ListView/">ListView</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/MD%E8%AF%AD%E6%B3%95/">MD语法</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/MyEclipse/">MyEclipse</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/OSS/">OSS</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/RecyclerView/">RecyclerView</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/SQL%E5%9F%BA%E7%A1%80/">SQL基础</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/UI%E6%8E%A7%E4%BB%B6/">UI控件</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/View/">View</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/ViewPager/">ViewPager</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/View%E7%AF%87/">View篇</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/as%E6%8A%A5%E9%94%99/">as报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/jar%E5%8C%85/">jar包</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/targetSdkVersion/">targetSdkVersion</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%B8%83%E7%89%9B%E4%BA%91/">七牛云</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%BA%8C%E7%BB%B4%E7%A0%81/">二维码</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%88%A0%E9%99%A4%E5%9B%BE%E7%89%87%E7%BC%93%E5%AD%98/">删除图片缓存</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/">升级报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/">博客搭建</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8E%BB%E6%8E%89v7%E5%8C%85/">去掉v7包</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/">图片处理</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%A4%9A%E5%AA%92%E4%BD%93/">多媒体</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%AE%9A%E5%88%B6%E7%B1%BB/">定制类</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B0%8F%E7%B1%B3%E6%89%8B%E6%9C%BA/">小米手机</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/">广播机制</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/">微博分享</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%89%93%E5%8C%85APK%E6%8A%A5%E9%94%99/">打包APK报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/">持久化存储</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%97%B6%E9%97%B4%E9%80%89%E6%8B%A9DatePicker/">时间选择DatePicker</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9C%8D%E5%8A%A1/">服务</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9D%83%E9%99%90/">权限</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/">构建基类</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%B5%8B%E8%AF%95/">测试</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%9B%91%E5%90%AC%E9%94%81%E5%B1%8F/">监听锁屏</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%B3%BB%E7%BB%9F%E9%A1%B5%E9%9D%A2%E8%B7%B3%E8%BD%AC/">系统页面跳转</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/">艺术探索</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%AF%BB%E5%8F%96txt/">读取txt</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%BE%93%E5%85%A5%E6%B3%95/">输入法</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E9%9F%B3%E4%B9%90%E6%92%AD%E6%94%BE%E5%99%A8/">音乐播放器</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E9%BB%91%E9%A9%AC%E5%8D%AB%E5%A3%AB/">黑马卫士</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Activity/" rel="tag">Activity</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android-Studio/" rel="tag">Android Studio</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android-Studio%E4%BB%8B%E7%BB%8D/" rel="tag">Android Studio介绍</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android%E5%9F%BA%E7%A1%80/" rel="tag">Android基础</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android%E6%A8%A1%E6%9D%BF/" rel="tag">Android模板</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/BaseRecyclerViewAdapterHelper/" rel="tag">BaseRecyclerViewAdapterHelper</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Bug%E9%97%AE%E9%A2%98/" rel="tag">Bug问题</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Button/" rel="tag">Button</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/EditText/" rel="tag">EditText</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Fragment/" rel="tag">Fragment</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Gradle/" rel="tag">Gradle</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ListView/" rel="tag">ListView</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MD%E8%AF%AD%E6%B3%95/" rel="tag">MD语法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MyEclipse/" rel="tag">MyEclipse</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/OSS/" rel="tag">OSS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RecyclerView/" rel="tag">RecyclerView</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SQL%E5%9F%BA%E7%A1%80/" rel="tag">SQL基础</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/UI%E6%8E%A7%E4%BB%B6/" rel="tag">UI控件</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/View/" rel="tag">View</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ViewPager/" rel="tag">ViewPager</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/View%E7%AF%87/" rel="tag">View篇</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/as%E6%8A%A5%E9%94%99/" rel="tag">as报错</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jar%E5%8C%85/" rel="tag">jar包</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/targetSdkVersion/" rel="tag">targetSdkVersion</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%B8%83%E7%89%9B%E4%BA%91/" rel="tag">七牛云</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/" rel="tag">升级报错</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" rel="tag">博客搭建</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/" rel="tag">图片处理</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%A4%9A%E5%AA%92%E4%BD%93/" rel="tag">多媒体</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B7%A5%E4%BD%9C%E9%97%AE%E9%A2%98/" rel="tag">工作问题</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/" rel="tag">广播机制</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BA%94%E7%94%A8%E8%AF%A6%E6%83%85/" rel="tag">应用详情</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/" rel="tag">微博分享</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/" rel="tag">持久化存储</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9C%8D%E5%8A%A1/" rel="tag">服务</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9D%83%E9%99%90/" rel="tag">权限</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/" rel="tag">构建基类</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%94%9F%E6%B4%BB/" rel="tag">生活</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BB%83%E6%89%8B/" rel="tag">练手</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/" rel="tag">艺术探索</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%BE%93%E5%85%A5%E6%B3%95/" rel="tag">输入法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%AB%98%E7%BA%A7%E6%8A%80%E5%B7%A7/" rel="tag">高级技巧</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Activity/" style="font-size: 12.5px;">Activity</a> <a href="/tags/Android-Studio/" style="font-size: 10px;">Android Studio</a> <a href="/tags/Android-Studio%E4%BB%8B%E7%BB%8D/" style="font-size: 12.5px;">Android Studio介绍</a> <a href="/tags/Android%E5%9F%BA%E7%A1%80/" style="font-size: 20px;">Android基础</a> <a href="/tags/Android%E6%A8%A1%E6%9D%BF/" style="font-size: 10px;">Android模板</a> <a href="/tags/BaseRecyclerViewAdapterHelper/" style="font-size: 10px;">BaseRecyclerViewAdapterHelper</a> <a href="/tags/Bug%E9%97%AE%E9%A2%98/" style="font-size: 10px;">Bug问题</a> <a href="/tags/Button/" style="font-size: 10px;">Button</a> <a href="/tags/EditText/" style="font-size: 10px;">EditText</a> <a href="/tags/Fragment/" style="font-size: 18.75px;">Fragment</a> <a href="/tags/Gradle/" style="font-size: 10px;">Gradle</a> <a href="/tags/ListView/" style="font-size: 17.5px;">ListView</a> <a href="/tags/MD%E8%AF%AD%E6%B3%95/" style="font-size: 11.25px;">MD语法</a> <a href="/tags/MyEclipse/" style="font-size: 13.75px;">MyEclipse</a> <a href="/tags/OSS/" style="font-size: 11.25px;">OSS</a> <a href="/tags/RecyclerView/" style="font-size: 12.5px;">RecyclerView</a> <a href="/tags/SQL%E5%9F%BA%E7%A1%80/" style="font-size: 10px;">SQL基础</a> <a href="/tags/UI%E6%8E%A7%E4%BB%B6/" style="font-size: 15px;">UI控件</a> <a href="/tags/View/" style="font-size: 10px;">View</a> <a href="/tags/ViewPager/" style="font-size: 10px;">ViewPager</a> <a href="/tags/View%E7%AF%87/" style="font-size: 10px;">View篇</a> <a href="/tags/as%E6%8A%A5%E9%94%99/" style="font-size: 10px;">as报错</a> <a href="/tags/jar%E5%8C%85/" style="font-size: 10px;">jar包</a> <a href="/tags/targetSdkVersion/" style="font-size: 10px;">targetSdkVersion</a> <a href="/tags/%E4%B8%83%E7%89%9B%E4%BA%91/" style="font-size: 10px;">七牛云</a> <a href="/tags/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/" style="font-size: 10px;">升级报错</a> <a href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" style="font-size: 12.5px;">博客搭建</a> <a href="/tags/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/" style="font-size: 15px;">图片处理</a> <a href="/tags/%E5%A4%9A%E5%AA%92%E4%BD%93/" style="font-size: 12.5px;">多媒体</a> <a href="/tags/%E5%B7%A5%E4%BD%9C%E9%97%AE%E9%A2%98/" style="font-size: 16.25px;">工作问题</a> <a href="/tags/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/" style="font-size: 12.5px;">广播机制</a> <a href="/tags/%E5%BA%94%E7%94%A8%E8%AF%A6%E6%83%85/" style="font-size: 10px;">应用详情</a> <a href="/tags/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/" style="font-size: 10px;">微博分享</a> <a href="/tags/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/" style="font-size: 13.75px;">持久化存储</a> <a href="/tags/%E6%9C%8D%E5%8A%A1/" style="font-size: 12.5px;">服务</a> <a href="/tags/%E6%9D%83%E9%99%90/" style="font-size: 10px;">权限</a> <a href="/tags/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/" style="font-size: 10px;">构建基类</a> <a href="/tags/%E7%94%9F%E6%B4%BB/" style="font-size: 11.25px;">生活</a> <a href="/tags/%E7%BB%83%E6%89%8B/" style="font-size: 11.25px;">练手</a> <a href="/tags/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/" style="font-size: 10px;">艺术探索</a> <a href="/tags/%E8%BE%93%E5%85%A5%E6%B3%95/" style="font-size: 10px;">输入法</a> <a href="/tags/%E9%AB%98%E7%BA%A7%E6%8A%80%E5%B7%A7/" style="font-size: 11.25px;">高级技巧</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">November 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">October 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">September 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">August 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">July 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">June 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">April 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/">March 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/02/">February 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/09/">September 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/10/">October 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/04/">April 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/01/">January 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2012/05/">May 2012</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/11/03/Android%20Studio/Github%E4%B8%8A%E6%8F%90%E4%BA%A4%E4%BB%A3%E7%A0%81/">Github上提交代码</a>
          </li>
        
          <li>
            <a href="/2017/10/31/RecyclerView/BaseRecyclerViewAdapterHelper%E5%BA%93%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95/">BaseRecyclerViewAdapterHelper库的基本使用方法</a>
          </li>
        
          <li>
            <a href="/2017/10/31/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/%E4%B8%83%E7%89%9B%E4%BA%91--%E4%B8%83%E7%89%9B%E4%BA%91%E5%BF%AB%E9%80%9F%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87/">七牛云快速上传图片</a>
          </li>
        
          <li>
            <a href="/2017/10/31/Gradle/Gradle--Gradle%E6%B7%BB%E5%8A%A0%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93%E6%8A%A5%E5%BC%82%E5%B8%B8/">Gradle添加第三方库报异常</a>
          </li>
        
          <li>
            <a href="/2017/10/26/Android%20Studio/%E8%A7%A3%E5%86%B3Android-Studio-Gradle-%E9%94%99%E8%AF%AF-%E7%BC%96%E7%A0%81GBK%E7%9A%84%E4%B8%8D%E5%8F%AF%E6%98%A0%E5%B0%84%E5%AD%97%E7%AC%A6/">解决Android Studio Gradle 错误 编码GBK的不可映射字符</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 wxyass<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.4.1.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>